package On_class.L0415;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;

public class Jdbc2 {

    public static void main(String[] args) throws Exception {
        String url="jdbc:mysql://localhost:3306/jdbc?serverTimezone=GMT%2B8";
        String user="root";
        String password="2001hong";
        Connection conn = DriverManager.getConnection(url,user,password);
        String sql1="insert into user(name) values(?)";
        String sql2="delete from user where id=? and name=?";
        String sql3="select * from user";

        PreparedStatement pstmt1=conn.prepareStatement(sql1);
        pstmt1.setString(1,"6");
        int i=pstmt1.executeUpdate();
        System.out.println(i);

        PreparedStatement pstmt2=conn.prepareStatement(sql2);
        pstmt2.setString(1,"王一");
        pstmt2.setString(2,"王二");
        i=pstmt2.executeUpdate();
        System.out.println(i);

        PreparedStatement pstmt3=conn.prepareStatement(sql3);

        i=pstmt2.executeUpdate();
        System.out.println(i);

        pstmt1.close();
        conn.close();
    }
}
